#include <stdio.h>

int main()
{
    FILE *fp = fopen("test.txt", "r"); // 文件指针

    if (fp == NULL)
    {
        perror("fopen");
        return -1;
    }

    char buf1[100] = {0};
    int read_ret1 = fread(buf1, 2, 4, fp); // 读取文件

    printf("ret1 = %d %s\n", read_ret1, buf1);

    int res1 = feof(fp);   // 判断是否到达文件末尾    0:不正常文件结束 1:正常文件结束
    int res2 = ferror(fp); // 判断是否出错           0:未出错 1:出错

    printf("fread res1 = %d res2 = %d\n", res1, res2);

    printf("tell = %ld\n", ftell(fp)); // 获取文件指针位置

    fseek(fp, 0, SEEK_SET); // 将文件指针移动到文件开头
    // SEEK_SET: 文件开头
    // SEEK_CUR: 文件当前位置
    // SEEK_END: 文件末尾

    printf("tell = %ld\n", ftell(fp));     // 获取文件指针位置
    int read_ret2 = fread(buf1, 3, 4, fp); // 读取文件

    printf("ret2 = %d %s\n", read_ret2, buf1);

    rewind(fp); // 将文件指针移动到文件开头

    printf("tell = %ld\n", ftell(fp)); // 获取文件指针位置

    fclose(fp);
}